﻿using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Lion.WeiXin.Core;
using Lion.WeiXin.Core.Data;
using Lion.WeiXin.Core.Models;
namespace Lion.WeiXin.Tests.Core
{
    [TestClass]
    public class CustomTaskTest
    {
        [TestMethod]
        public void ExecuteTest_GetBalance()
        {
            string funName = "GetBalance";
            string openId = "oCtEus3ZQj2zoA0zBiAvP-OLhkiA";
           string result=(string) CustomTask.Execute(funName, openId);
           Assert.AreEqual("尊敬的春春,您的卡号余额是：￥2691.80", result);
        }

        [TestMethod]
        public void ExecuteTest_ConfirmPaymentCode()
        {
            string funName = "ConfirmPaymentCode";
            string openId = "oCtEus3ZQj2zoA0zBiAvP-OLhkiA";
            string msg = "59798";
            string result = (string)CustomTask.Execute(funName, openId,msg);
            Assert.AreEqual("验证通过，订单支付成功！", result);
        }

        [TestMethod]
        public void testOpenid()
        {
            string openId = "oCtEus3ZQj2zoA0zBiAvP-OLhkiA";
            DBContext db = new DBContext();
            WeChatUserModel  model= db.WeChatUsers.GetModel(openId);
            Assert.AreEqual("100", model.VipCardCode);
        }
       [TestMethod]
        public void Test_default()
        {
            DBContext db = new DBContext();
            string where = string.Format("Keyword like '{0}%' and ActionType='{1}'", "23845", AutoReplyEnum.文本动作.ToString());
            AutoReplyModel rule = db.AutoReplys.GetList(1, where, "Sequence").FirstOrDefault();

            Assert.IsNull(rule);
        }

        [TestMethod]
        public void OrderID()
        { 
            string ids = "";
            for(int i=0;i<20;i++)
            {
                ids += Tools.StringHelper.GetUniqueID() + ",";
            }
            Assert.AreEqual("111",ids);
        }

        private string GetOID()
        {
            long i = 1;
            foreach (byte b in Guid.NewGuid().ToByteArray())
            {
                i *= ((int)b + 1);
            }
            return string.Format("{0:x}", i - DateTime.Now.Ticks);
        }

        private long GetNumberOID()
        {
            byte[] buffer = Guid.NewGuid().ToByteArray();
            return BitConverter.ToInt64(buffer, 0);
        }
    }
}
